package com.ctgu.springboot.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ctgu.springboot.common.Result;
import com.ctgu.springboot.entity.Admin;
import com.ctgu.springboot.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cs
 * @since 2023-07-07
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @RequestMapping("login")//系统管理员登录
    public Result getAdminByPassword(String adm_name, String adm_password){
        Map<String,Object> resultMap= new HashMap<>();
        QueryWrapper<Admin> adminQueryWrapper=new QueryWrapper<>();
        adminQueryWrapper.eq("adm_name",adm_name)
                .eq("adm_password",adm_password);
        if(adminService.getOne(adminQueryWrapper)!=null){
            Admin admin=adminService.getOne(adminQueryWrapper);
            String token = UUID.randomUUID().toString();
            resultMap.put("admin",admin);
            resultMap.put("token", token);
            return Result.suc(resultMap);
        }else{
            return Result.fail();
        }

    }

}
